import {
  IsBoolean,
  IsInt,
  IsNotEmpty,
  IsOptional,
  IsString,
} from "class-validator";
import {
  FileSystemStoredFile,
  IsFile,
  MaxFileSize,
  MemoryStoredFile,
} from "nestjs-form-data";

export const MAX_FILE_SIZE = 1024 * 1024 * 100;
export const MAX_CHUNK_SIZE = 1024 * 1024 * 100;

export class ResourceDTO {
  @IsString()
  @IsNotEmpty()
  name: string;

  @IsString()
  @IsOptional()
  description?: string;

  @IsOptional()
  public?: boolean | string;

  @IsFile()
  @MaxFileSize(MAX_FILE_SIZE) // 100MB
  file: MemoryStoredFile;
}

// 请求分片上传临时code
export class ResourceChunkCodeDTO {
  @IsString()
  @IsNotEmpty()
  name: string;

  @IsString()
  @IsOptional()
  description?: string;

  @IsString()
  @IsOptional()
  public?: boolean | string;
}

// 完成文件上传
export class ResourceChunkEndDTO {
  @IsString()
  @IsNotEmpty()
  code: string;
}

// 分片上传
export class ResourceChunkDTO {
  @IsString()
  @IsNotEmpty()
  code: string;

  @IsInt()
  @IsOptional()
  index?: number;

  @IsFile()
  @MaxFileSize(MAX_CHUNK_SIZE) // 100MB
  chunk: FileSystemStoredFile;
}
